package com.qidian.mes.om.service.impl;

import com.qidian.mes.om.mapper.DeptMapper;
import com.qidian.mes.om.service.DeptService;
import com.qidian.mes.pojo.Dept;
import com.qidian.mes.util.pojo.MESResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author 戴着假发的程序员
 * @Company 起点编程
 * @Time 2023/11/2 9:31
 * @Description
 */
@Service
public class DeptServiceImpl implements DeptService {
    @Autowired
    private DeptMapper deptMapper;
    @Override
    public MESResult listAll() {
        return MESResult.ok(listByParentId(0L));
    }

    private List<Dept> listByParentId(Long parentId){
        List<Dept> depts = deptMapper.queryByParentId(parentId);
        for (Dept dept :depts){
            if(dept.getParent().equals(new Integer(1))){
                dept.setChildren(listByParentId(dept.getDeptId()));
            }
        }
        return depts;
    }
}
